import React, { Component } from 'react';
import axios from 'axios';
interface InputComponentProps {
  // 这里可以定义你的组件属性，如果有的话  
}

interface InputComponentState {
  inputValue: string;
}

class InputComponent extends Component<InputComponentProps, InputComponentState> {
  constructor(props: InputComponentProps) {
    super(props);
    this.state = {
      inputValue: ''
    };

    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleChange(event: React.ChangeEvent<HTMLInputElement>) {
    this.setState({ inputValue: event.target.value });
  }

  handleSubmit(event: React.FormEvent<HTMLFormElement>) {
    event.preventDefault();
    console.log(this.state.inputValue);
    axios.get('http://localhost:3000/api/data') // 假设你的 NestJS 服务运行在 3000 端口  
      .then((response: any) => {
        console.log(response.data)
      })
      .catch((error: any) => {
        console.log(error)
      });

  }
  async componentDidMount() {

  }


  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <input
          type="text"
          value={this.state.inputValue}
          onChange={this.handleChange}
        />
        <button type="submit">提交</button>
      </form>
    );
  }
}

export default InputComponent;